﻿
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item active" aria-current="page">Projects</li>
    </ol>
</nav>

<a class="btn btn-primary" href="/Projects/Add" role="button">Add</a>

@foreach (var item in ViewBag.Projects)
{
<div class="row">
    <div class="col">
        <a href="/Projects/Details?projectid=@item.Id">@item.Name</a>
    </div>
    <div class="col">
        <span>@item.Code</span>
    </div>
    <div class="col">
        <a href="/Projects/Edit?projectid=@item.Id">Edit</a>
        <a href="javascript:buildProject('@item.Id')">Build</a>
        <a href="javascript:deleteProject('@item.Id')">Delete</a>
    </div>
</div>
}

@section Scripts{

    <script>
        function buildProject(projectid) {
            $.post("/Projects/BuildProject", { projectid: projectid }, function (res) {
                if (res.code == 1) {
                    location.reload();
                }
            });
        }
        function deleteProject(projectid) {
            $.post("/Projects/DeleteProject", { projectid: projectid }, function (res) {
                if (res.code == 1) {
                    location.reload();
                }
            });
        }

    </script>

}
